import 'package:duuchin/config/app_colors.dart';
import 'package:duuchin/utils/UserType.dart';
import 'package:flutter/material.dart';

class AvatarRoleName extends StatelessWidget {
  final String coverPictureUrl;
  final String nikename;
  final String type;
  final bool showType;

  const AvatarRoleName({
    Key key,
    this.coverPictureUrl,
    this.nikename,
    this.type,
    this.showType = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        _avatar(),
        Offstage(
          offstage: !showType,
          child: _role(),
        ),
        _nikename(),
      ],
    );
  }

  Widget _avatar() {
    return SizedBox(
      width: 18,
      height: 18,
      child: ClipOval(
        child: FadeInImage.assetNetwork(
            placeholder: 'assets/images/common/lazy-1.png',
            image: coverPictureUrl),
      ),
    );
  }

  Widget _role() {
    return Container(
      margin: EdgeInsets.only(left: 3),
      padding: EdgeInsets.symmetric(vertical: 2, horizontal: 4),
      decoration: BoxDecoration(
        color: UserType.formColor(type),
        borderRadius: BorderRadius.circular(4),
      ),
      child: Text(
        UserType.formCn(type),
        style: TextStyle(fontSize: 10, color: Colors.white),
      ),
    );
  }

  Widget _nikename() {
    return Expanded(
      child: Container(
        margin: EdgeInsets.only(left: 4),
        child: Text(
          nikename,
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
          style: TextStyle(color: AppColors.unactive, fontSize: 13),
        ),
      ),
    );
  }
}
